"""
Django 项目配置文件
"""
from pathlib import Path

# 项目根目录
BASE_DIR = Path(__file__).resolve().parent.parent

# 开发设置（生产环境需修改）
SECRET_KEY = 'django-insecure-w_b*l15p9)t(^&*#dh&+9!ozfiqus5k$me97b0z2^c%ef9a%k7'  # 密钥，生产环境要保密
DEBUG = True  # 调试模式，生产环境设为 False
ALLOWED_HOSTS = ['*']  # 允许访问的域名，如 ['*'] 或 ['example.com']

# 已安装的应用
INSTALLED_APPS = [
    "daphne",
    "channels",
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tailwind',  # Tailwind CSS 支持
    'theme',
    'app.apps.AppConfig',
]

TAILWIND_APP_NAME = 'theme'
NPM_BIN_PATH = "/root/.nvm/versions/node/v24.6.0/bin/npm"

# 中间件（请求处理链）
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'MyDjangoProject.urls'

# 模板配置
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],  # 自定义模板目录
        'APP_DIRS': True,  # 允许应用内查找模板
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

# WSGI_APPLICATION = 'MyDjangoProject.wsgi.application'

# 数据库配置（SQLite）
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',  # 数据库文件路径
    }
}


# 使用 channels 来处理 WebSocket
ASGI_APPLICATION = 'MyDjangoProject.asgi.application'


# CHANNEL_LAYERS = {
#     'default': {
#         'BACKEND': 'channels_redis.core.RedisChannelLayer',
#         'CONFIG': {
#             "hosts": [
#                 {
#                     "address": ('10.54.3.58', 6379),
#                     "password": 'bzr123456',
#                     "username": 'default',  # Redis 6 及以上版本需要
#                 },
#             ],
#         },
#     },
# }

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    }
}


# 密码校验规则
AUTH_PASSWORD_VALIDATORS = [
    {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
    {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
    {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
    {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
]

# 国际化设置
LANGUAGE_CODE = 'zh-hans'  # 中文（简体）
TIME_ZONE = 'Asia/Shanghai'  # 中国时区
USE_I18N = True  # 启用国际化
USE_TZ = True  # 启用时区支持

# 静态文件配置
STATIC_URL = '/static/'  # 静态文件URL前缀

# 默认主键类型
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# 终端 1：Tailwind 编译服务（监听并生成 CSS）
# python manage.py tailwind start
